package dwarffortess.web.research;

import dwarffortress.loaders.RawLoader;
import dwarffortress.loaders.LanguageLoader;
import dwarffortress.loaders.ReflectiveLoader;
import dwarffortress.data.DFLanguageWord;
import dwarffortress.data.DFUnitElement;
import dwarffortress.io.DFInputStream;

import java.io.*;
import java.util.Map;

public class TestMain {
    public static void main(String[] args) throws IOException, InstantiationException, IllegalAccessException {
        File[] files = new File(".").listFiles(new FileFilter() {
            public boolean accept(File pathname) {
                return !pathname.isDirectory();
            }
        });
        ReflectiveLoader loader = new ReflectiveLoader();
        for (File f : files) {
            System.out.printf("%-24s : ", f.getName());
            InputStream in = new BufferedInputStream(new FileInputStream(f));
            DFInputStream dfin = new DFInputStream(in);
            DFUnitElement element = loader.loadObject(DFUnitElement.class, dfin);
            dfin.attachOutput(new FileOutputStream("rest/" + f.getName()));
            byte[] next = new byte[8];
            int count = dfin.read(next);
            for (int i = 0; i < count; i++) {
                System.out.printf("%02x ", next[i] & 0xff);
            }
            do {

            } while (dfin.read() >= 0);
            dfin.detachOutput().close();
            in.close();
            System.out.println();
        }
    }
}
